package org.example.im.common.util;

import io.netty.channel.Channel;
import io.netty.util.Attribute;
import lombok.experimental.UtilityClass;
import org.example.im.common.attribute.Attr;

import java.util.Objects;

/**
 * @author dingrui
 * @since 2022/2/11
 * @description
 */
@UtilityClass
public class LoginUtil {

    public boolean hasLogin(Channel c) {
        Attribute<Boolean> loginAttr = c.attr(Attr.LOGIN);
        return Objects.nonNull(loginAttr) && Objects.equals(loginAttr.get(), Boolean.TRUE);
    }

    public void markAsLogin(Channel c) {
        c.attr(Attr.LOGIN).set(true);
    }
}
